//
//  SNInfoView.m
//  project
//
//  Created by 圆圆陈 on 2018/1/20.
//  Copyright © 2018年 黄建华. All rights reserved.
//

#import "SNInfoView.h"

@interface SNInfoView ()
@property(nonatomic,strong)UILabel *contentLabel;
@property(nonatomic,strong)UILabel *dateLabel;
@end
@implementation SNInfoView

-(instancetype)initWithFrame:(CGRect)frame withType:(NSInteger)type{
    if (self=[super initWithFrame:frame]) {
        NSArray *titleArr = @[HHH_Text(@"最佳单日纪录"),HHH_Text(@"连续达标天数"),HHH_Text(@"最佳星期"),HHH_Text(@"最佳月份")];
        NSArray *imageArr = @[@"个人最佳记录",@"连续达标天数",@"最佳星期",@"最佳月份"];
        _type = type;
        
        UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.width, self.height/4)];
        titleLabel.textColor = SNCOLORBLACK;
        
        titleLabel.font = SNFONT(17);
        titleLabel.text = titleArr[type];
        [self addSubview:titleLabel];
        
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, titleLabel.bottom -3, self.width/3*0.8, self.height*3/4 *0.8)];
        [imageView setImage:UIImageNamed(imageArr[type])];
        imageView.contentMode = UIViewContentModeScaleAspectFit;
        [self addSubview:imageView];
        
        _contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(imageView.right+10, titleLabel.bottom +5, self.width*2/3-10, self.height*3/8-10)];
        _contentLabel.textColor = SNCOLORBLACK;
        _contentLabel.font =SNFONT(15);
        [self addSubview:_contentLabel];
        
        _dateLabel = [[UILabel alloc]initWithFrame:CGRectMake(imageView.right+10, _contentLabel.origin.y +18, self.width*2/3-10, self.height*3/8-10)];
        _dateLabel.textColor = SNCOLORGRAY;
        _dateLabel.font = SNFONT(11.5);
        [self addSubview:_dateLabel];
        
    }
    return self;
}
-(void)setContentStr:(NSString *)contentStr{
    _contentStr = contentStr;
    _contentLabel.attributedText = [self changeLabelWithText:_contentStr];
}
-(void)setDateStr:(NSString *)dateStr{
    _dateStr = dateStr;
    _dateLabel.text = _dateStr;
}
-(NSMutableAttributedString*)changeLabelWithText:(NSString*)string
{
    NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:string];
    UIFont *font = SNFONTMIN(FitFont(12));
    for (int i = 0; i <string.length; i++) {
        unichar ch = [string characterAtIndex:i];
        if (!('0' <= ch && ch <= '9')) {
            NSRange range = {i, 1};
            [attrString addAttribute:NSFontAttributeName value:font range:range];
        }
    }
    return attrString;
}
@end
